import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        title: '承接顾问',
        field: 'userName',
        minWidth: 150,
        fixed: 'left',
        slots: {
          header: (params, h) => {
            return table.header.arrow(
              _this,
              h,
              nameOpt.createPeople({
                key: 'userName',
                title: '承接顾问',
                to: (info) => {
                  return {
                    nameOrWorkNo: info.workNo
                  }
                }
              })
            )
          }
        }
      },
      {
        field: 'buildingType',
        minWidth: 120,
        header: {
          filter: {
            title: '是否在案',
            key: 'buildingType',
            placeholder: '请选择是否在案',
            select: {
              options: [
                { key: 1, value: '在案' },
                { key: 2, value: '离案' }
              ]
            }
          }
        },
        slots: {
          default: (params, h) => {
            return [h('div', params.row.buildingType == 2 ? '离案' : '在案')]
          }
        }
      },
      {
        title: '总线索量',
        field: 'totalClueNum',
        minWidth: 150
      },
      {
        title: '总承接',
        field: 'totalReceiveNum',
        minWidth: 150
      },
      {
        title: '平均承接时长',
        field: 'averageReceiveTime',
        minWidth: 150
      },
      {
        title: '总承接率',
        field: 'averageReceiveRate',
        minWidth: 150
      },
      {
        title: '来电数量',
        field: 'callInNum',
        minWidth: 150
      },
      {
        title: '已接数量',
        field: 'answersNum',
        minWidth: 150
      },
      {
        title: '接听率',
        field: 'answersRate',
        minWidth: 150
      },
      {
        title: '平均接电时长',
        field: 'averageAnswersTime',
        minWidth: 150
      },
      {
        title: '表单数量',
        field: 'formNum',
        minWidth: 150
      },
      {
        title: '表单回拨量',
        field: 'formCallBackNum',
        minWidth: 150
      },
      {
        title: '表单承接率',
        field: 'formCallBackRate',
        minWidth: 150
      },
      {
        title: '平均回拨时长',
        field: 'averageFormCallBackTime',
        minWidth: 150
      },
      {
        title: '转到访数',
        field: 'toVisitNum',
        minWidth: 150
      },
      {
        title: '转到访率',
        field: 'toVisitRate',
        minWidth: 150
      },
      {
        title: '所属事业部',
        field: 'caseLocation',
        minWidth: 150
      },
      {
        title: '所属子公司',
        field: 'caseLocationTwo',
        minWidth: 150
      },
      {
        title: '所属事业处',
        field: 'department',
        minWidth: 150
      },
      {
        title: '所属案场',
        field: 'housesName',
        minWidth: 150
      },
      {
        title: '所属城市',
        field: 'city',
        minWidth: 150
      },
      {
        field: 'receiverCreateTime',
        minWidth: 150,
        title: '承接配置时间',
        header: {
          filter: dateOpt.range({
            title: '承接配置时间',
            startKey: 'setStartTime',
            endKey: 'setEndTime',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.setStartTime, val.setEndTime).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('签约日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.setStartTime, val.setEndTime).Y >= 2)
            }
          })
        }
      },
      {
        title: '运营配置人',
        field: 'receiverCreator',
        minWidth: 150
      },

      {
        title: '操作',
        fixed: 'right',
        width: 280,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = []
            console.log(_this.isReceiving, 'isReceivingisReceiving')
            btns.push({
              title: '查看',
              event: 'checkFun',
              data: params.row
            })

            btns.push({
              title: _this.isReceiving == 2 && _this.unlocking('0213020200') ? '编辑' : '',
              event: _this.isReceiving == 2 && _this.unlocking('0213020200') ? 'editFun' : '',
              data: params.row
            })
            btns.push({
              title: '通话记录',
              event: 'callRecord',
              data: params.row
            })
            btns.push({
              title: _this.isReceiving == 2 && _this.unlocking('0213020300') ? '删除' : '',
              event: _this.isReceiving == 2 && _this.unlocking('0213020300') ? 'delFun' : '',
              data: params.row
            })
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

export default Column
